﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace Maticsoft.Web
{
    public partial class Detail : PageBase
    {
        int _ChannelId;
        int _ClassId;
        int _Id;
        public Model.Books model;
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["channelId"], out _ChannelId);
            int.TryParse(Request.QueryString["classId"], out _ClassId);
            int.TryParse(Request.QueryString["id"], out _Id);
            if (_ChannelId != 0 && _ClassId != 0)
            {
                BindData();
                GetNav();
                GetSiteInfo();
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void BindData()
        {
            BLL.Books booksBll = new BLL.Books();
            model = booksBll.GetModel(_Id);
            Title = model.BookName;

            GetProductPic();
        }

        /// <summary>
        /// 获取产品图片
        /// </summary>
        protected void GetProductPic()
        {
            BLL.BookPics bookPicsBll = new BLL.BookPics();
            DataSet ds = bookPicsBll.GetList("bookId=" + _Id);
            StringBuilder strBuilderBig = new StringBuilder();
            StringBuilder strBuilderSmall = new StringBuilder();
            strBuilderBig.Append("<ul class=\"cf\">");
            strBuilderSmall.Append("<ul class=\"cf\">");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                strBuilderBig.Append("<li><img src=\"uploadpic/small/" + ds.Tables[0].Rows[i]["pic"].ToString() + "\" width=\"500\" height=\"500\" /></li>");
                if (i == 0)
                {
                    strBuilderSmall.Append("<li class=\"on\"><i class=\"arr2\"></i><img src=\"uploadpic/small/" + ds.Tables[0].Rows[i]["pic"].ToString() + "\" /></li>");
                }
                else
                {
                    strBuilderSmall.Append("<li><i class=\"arr2\"></i><img src=\"uploadpic/small/" + ds.Tables[0].Rows[i]["pic"].ToString() + "\" /></li>");
                }
            }
            strBuilderBig.Append("</ul>");
            strBuilderSmall.Append("</ul>");

            ltlBig.Text = strBuilderBig.ToString();
            ltlSmall.Text = strBuilderSmall.ToString();
        }

        #region 获取导航
        protected void GetNav()
        {
            GetNavigate(_ClassId);
            nav.InnerHtml = strNav;
        }

        string strNav = string.Empty;
        BLL.Channel channelBll = new BLL.Channel();
        Model.Channel channelModel = null;
        protected void GetNavigate(int channelId)
        {
            channelModel = channelBll.GetModel(channelId);
            if (!string.IsNullOrEmpty(strNav))
            {
                strNav = channelModel.ChannelName + " > " + strNav;
            }
            else
            {
                strNav = channelModel.ChannelName;
            }
            if (channelModel.ParentId != 0)
            {
                GetNavigate((int)channelModel.ParentId);
            }
            else
            {
                strNav = "&nbsp; 首页 > " + strNav;
            }
        }
        #endregion

        protected void GetSiteInfo()
        {
            BLL.WebSiteConfig bll = new BLL.WebSiteConfig();
            Model.WebSiteConfig model = bll.GetModelByCache(1);
            Title += "-" + model.SiteName;
            MetaKeywords = model.KeyWords;
            MetaDescription = model.Description;
        }
    }
}